import store from '../../store/store'

//获取该小程序下的所有用户
export const findAllUserByMiniKeyApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post(`/api/miniApp/findAllUserByMiniKey`, data)
	return res
}
//分页查询慢性病
export const getChronicListApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post(`/api/chronicDisease/miniApp/findListByPage`, data)
	return res
}

//查询慢性病详情
export const getChronicDetailApi = async (id) => {
	const {
		data: res
	} = await uni.$http.get(`/api/chronicDisease/miniApp/queryOneDetail/${id}`)
	return res
}

//新增/编辑慢性病
export const addChronicApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/chronicDisease/miniApp/addChronicDisease', data)
	return res
}

//删除慢性病
export const delChronicApi = async (ids) => {
	const {
		data: res
	} = await uni.$http.DELETE(`/api/chronicDisease/miniApp/deleteChronicDisease/${ids}`)
	return res
}

//分页查询健康数据
export const getUserHealthListApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/healthData/miniApp/findListByPage', data)
	return res
}

// 新增/编辑 健康数据
export const addHealthApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/healthData/miniApp/addHealthData', data)
	return res
}

//查询单个健康数据详情
export const getHealthApi = async (id) => {
	const {
		data: res
	} = await uni.$http.get(`/api/healthData/miniApp/queryOneDetail/${id}`)
	return res
}


//删除单个健康数据
export const delHealthApi = async (ids) => {
	const {
		data: res
	} = await uni.$http.delete(`/api/healthData/miniApp/deleteHealthData/${ids}`)
	return res
}

//获取用户详情
export const getUserInfoApi = async () => {
	const {
		data: res
		// } = await uni.$http.post(`/api/miniApp/querySingleDetail/${id}`)
	} = await uni.$http.post('/api/auth/getUserInfo')
	return res
}

//新增/编辑用户详情
export const editUserInfoApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/miniApp/addMiniAppMember', data)
	return res
}

//分页条件查找小程序用户数据
export const getSalesmanInfoApi = async (phone, enterpriseCode) => {
	const {
		data: res
	} = await uni.$http.post('/api/miniApp/findListPage', {
		phone,
		enterpriseCodes: [enterpriseCode]
	})
	return res
}

//查询所有亲情号
export const getFamilyListApi = async (memberCode) => {
	const {
		data: res
	} = await uni.$http.post(`/api/miniApp/findAllFamily/${memberCode}`)
	return res
}


//新增亲情号
export const addFamilyApi = async (memberCode, data) => {
	const {
		data: res
	} = await uni.$http.post(`/api/miniApp/miniApp/addFamilyNumber/${memberCode}`, data)
	return res
}

//删除亲情号
export const delFamilyApi = async (memberCode, relationCode) => {
	const {
		data: res
	} = await uni.$http.post(`/api/miniApp/miniApp/deleteRelation/${memberCode}/${relationCode}`)
	return res
}

//查询所有启用轮播图信息
export const getBannerApi = async (enterpriseCode) => {
	const {
		data: res
	} = await uni.$http.get('/api/flash/wx/queryList', {
		enterpriseCode
	})
	return res
}

//获取access_token 
export const getAccessTokenApi = async () => {
	const key = uni.getStorageSync('ylProject').miniKey
	const res = await uni.$http.get(`/api/miniApp/config/getAccessToken/${key}`)
	if (res.data.status === 200) {
		return res.data.data
	} else {
		return uni.$showMsg(res.data.message)
	}
}

//生成小程序码
export const getminiCodeApi = async () => {
	// 	//传的实际是用户id, 用来在亲情号登录流程中, 获取memberCode
	uni.$http.responseType = 'arraybuffer'
	const key = uni.getStorageSync('ylProject').miniKey
	const res = await uni.$http.get(`/api/miniApp/config/createIndividualQrUrl/${key}`)
	let url = 'data:image/png;base64,' + uni.arrayBufferToBase64(res.data)
	uni.$http.responseType = ''
	return url
}

//根据appid查询项目
export const getProjectCodeApi = async () => {
	const {
		data: res
	} = await uni.$http.post(`/api/miniApp/config/queryByAppId/${uni.getAccountInfoSync().miniProgram.appId}`)
	return res.data
}
//获取用户协议 
export const getAgreementApi = async (key) => {
	const {
		data: res
	} = await uni.$http.get(`/api/miniApp/getAgreement/${key}`)
	return res
}

//  根据字典类型查询字典信息
export const findDictsApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post(`/api/systemDictData/findDictData`,data)
	return res
}
